
//
// 110917 - AH - (Midtun) Created.
// 110919 - AH - Finished first version with all java doc, meaningful names.
// 120122 - AH - (Chaos) Is retrieval: Must extends AttributeObject stupid.
//

package org.soekrat.engine.ontology.ptable;

import org.soekrat.AttributeObject;
import org.soekrat.engine.SoekratName;

/**
 * <p>
 *   A product in a
 *   {@link ProductTable}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class Product extends AttributeObject 
{
  private SoekratName m_row;
  
  private SoekratName m_col;
  
  private SoekratName m_sname;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param row    Row factor's name.
   * @param col    Column factor's name.
   * @param sname {@link SoekratName}.
   */
  Product(SoekratName row, SoekratName col, SoekratName sname)
  {
    if (row==null)
    {
      throw new NullPointerException("f0");
    }
    if (col==null)
    {
      throw new NullPointerException("f1");
    }
    if (sname==null)
    {
      throw new NullPointerException("sname");
    }
    
    m_row=row;
    m_col=col;
    m_sname=sname;
  }
 
  /**
   * <p>
   *   Gets the 
   *   {@link SoekratName}.
   * </p>
   * @return {@code SoekratName}.
   */
  public SoekratName getSoekratName(){ return m_sname; }
  
  /**
   * <p>
   *   Sets name.
   * </p>
   * @param name Name.
   */
  public void setSoekratName(String name)
  {
    name=(name==null) ? "" : name.trim();
    if (name.length()==0)
    {
      throw new IllegalArgumentException("name not given");
    }
    
    m_sname=new SoekratName(name);
  }
  
  /**
   * <p>
   *   Gets row factor of {@code this} product.
   * </p>
   * @return Factor.
   */
  public SoekratName getRowFactor(){ return m_row; }
  
  /**
   * <p>
   *   Gets column factor of {@code this} product.
   * </p>
   * @return Factor.
   */
  public SoekratName getColFactor(){ return m_col; }
  
  /**
   * <p>
   *   Gets keys that identifies this as a product in a
   *   {@link ProductTable}.
   * </p>
   * <p>
   *   Implementation detail, not exposed in public interface outside package.
   * </p>
   * @return Key.
   */
  String getProductKey(){ return ProductTable.getKey(m_row, m_col); }
  
  @Override
  public String toString()
  {
    StringBuilder sb=new StringBuilder();
    return sb.append(m_row).append(" x ").append(m_col).append(" = ")
      .append(m_sname).toString();
  }

}
